<?xml version="1.0" encoding="UTF-8"?>
<!--
    Copyright (c) 2009 Mitch Amiano (Mitch.C.Amiano@AgileMarkup.com)
    
    Permission is hereby granted, free of charge, to any person obtaining a copy
    of this software and associated documentation files (the "Software"), to deal
    in the Software without restriction, including without limitation the rights
    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    copies of the Software, and to permit persons to whom the Software is
    furnished to do so, subject to the following conditions:
    
    The above copyright notice and this permission notice shall be included in
    all copies or substantial portions of the Software.
    
    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    THE SOFTWARE.
-->

<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xlink="http://www.w3.org/1999/xlink"
    xmlns:svg="http://www.w3.org/2000/svg"
    xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
    xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:xhtml="http://www.w3.org/1999/xhtml"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt"
    exclude-result-prefixes="xlink msxsl exsl inkscape sodipodi svg am xhtml" 
    xmlns:exsl="http://exslt.org/common"
    xmlns:am="http://www.agilemarkup.com/2009/xmlintegration"
    xmlns:amd="http://www.agilemarkup.com/2009/xmlintegration"
    extension-element-prefixes="exsl amd"
    >
    
    <amd:purpose>This stylesheet module provides the JavaScript and HTML which together
        allow SVG to be displayed in IE browsers. 
        It is meant to be imported by the atramentum.xsl module. 
        You can think of this file as an implementation of an abstract interface:
        splinter_init   output the script element for forcing SVG on IE
        splinter_content   output the html code for the SVG objects
        splinter    output an svg file for each widget
    </amd:purpose>

    <!-- include code to force broken microsoft browsers to display SVG images -->
    <xsl:template name="splinter_init">
        <xsl:comment>To use SVG Web this must be the first script tag on your page:</xsl:comment>
        <script src="svgweb/src/svg.js" data-path="svgweb/src"><![CDATA[ ]]></script>
    </xsl:template>
    
    <xsl:template match="svg:g[ svg:rect[contains(@id,'_img')] ]"  mode="splinter_content">
        <xsl:comment>
            <xsl:text>[if IE]&gt;&#xA;</xsl:text>
            <xsl:text>&lt;object src="{@id}.png" classid="image/svg+xml" width="200" height="200" id="{@id}"&gt;&#xA;</xsl:text>
            <xsl:text>&lt;![endif]</xsl:text>
        </xsl:comment>
        <xsl:comment>[if !IE]&gt;</xsl:comment>
        <object data="{@id}.png" type="image/svg+xml" width="200" height="200" id="{@id}">
            <xsl:comment>&lt;![endif]</xsl:comment>
        </object>
        <xsl:text>&#xA;</xsl:text>
    </xsl:template>
    
    <am:purpose>Create an SVG file containing the current node and its content.</am:purpose>
    <xsl:template match="svg:g[ svg:rect[contains(@id,'_img')] ]" mode="splinter">
        <exsl:document href="{$base_dir}/{@id}.svg" method="xml" encoding="UTF-8" 
            media-type="image/svg+xml"  
            >
            <svg:svg>
                <xsl:copy-of select="/svg:svg/@*"/>
                <svg:g>
                    <xsl:apply-templates select="node()|@*" mode="splinter" />
                </svg:g>
            </svg:svg>
            <xsl:text>&#xA;</xsl:text>
        </exsl:document>
    </xsl:template>
    
    <xsl:template match="node() | @*" mode="splinter">
        <xsl:copy>
            <xsl:apply-templates select="node() | @*" mode="splinter"/>
        </xsl:copy>
    </xsl:template>  
</xsl:stylesheet>
